import sys

result = {}
for line in sys.stdin:
    line = line.strip()  # 记得去空格和换行！
    x, y = line.split(' ')
    if x in result:
        result[x].append(y)
    else:
        result[x] = [y]

for i in result:
    print(i, result[i])

# type friends.txt | python map_2.py | python reduce_2.py